from launch import LaunchDescription
from launch_ros.actions import Node
#封装终端指令相关类--------------
#from launch.actions import ExecuteProcess
#from launch.substitutions import FindExecutable
#参数声明与获取-----------------
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
#文件包含相关-------------------
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
#分组相关----------------------
#from launch_ros.actions import PushRosNamespace
#from launch.actions import GroupAction
#事件相关----------------------
#from launch.event_handlers import OnProcessStart,OnProcessExit
#from launch.actions import ExecuteProcess,RegisterEventHandler,LogInfo
#获取功能包下share目录路径-------
from ament_index_python.packages import get_package_share_directory
import os
def generate_launch_description():
    fishbot_navigation2_dir=get_package_share_directory(
        "fishbot_navigation2"
    )
    nav2_bringup_dir=get_package_share_directory("nav2_bringup")
    rviz_config_dir=os.path.join(nav2_bringup_dir,"rviz","nav2_default_view.rviz")
   
    use_sim_time=LaunchConfiguration("use_sim_time",default="true")
    
   
    map_yaml_path=LaunchConfiguration("map",
    default=os.path.join(fishbot_navigation2_dir,"map","room.yaml"))
    
   
    nav2_param_path=LaunchConfiguration("param_file",
    default=os.path.join(fishbot_navigation2_dir,"config","nav2_params.yaml"))                 
    
    return LaunchDescription([ 
        DeclareLaunchArgument("use_sim_time",default_value="true",
        description="Use simulation (Gazebo) clock if true"),
        DeclareLaunchArgument("map",default_value=os.path.join(fishbot_navigation2_dir,"map","room.yaml"),
        description="Full path to map file to load"),
        DeclareLaunchArgument("param_file",default_value=os.path.join(fishbot_navigation2_dir,"config","nav2_params.yaml"),
        description="Full path to prama file to load"),
        
        IncludeLaunchDescription(PythonLaunchDescriptionSource(
            [nav2_bringup_dir,"/launch","/bringup_launch.py"]),
            launch_arguments={
                "map":map_yaml_path,
                "use_sim_time":use_sim_time,
                "params_file":nav2_param_path}.items()
        ),
        Node(
            package="rviz2",
            executable="rviz2",
            name="rviz2",
            arguments=["-d", rviz_config_dir],
            parameters=[{"use_sim_time":use_sim_time}],
            output="screen") 
        ])